//
//  FQOrganizationPhoneViewController.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/9/5.
//

import UIKit

class FQOrganizationPhoneViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {
    let mainTable = UITableView(frame: .zero, style: .plain)
    
    let headerView = FQOrganizationPhoneHeaderView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarType = .light
    }
    
    override func initSubviews() {
        super.initSubviews()
        
        headerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageTap)))
        view.addSubview(headerView)
        
        headerView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(NavigationContentTop)
            make.height.equalTo(152)
        }
//        mainTable.dataSource = self
//        mainTable.delegate = self
//        mainTable.rowHeight = 52
//        mainTable.register(FQOrganizationPhoneTableViewCell.self, forCellReuseIdentifier: "cell")
//        mainTable.backgroundColor = view.backgroundColor
//        mainTable.register(FQOrganizationPhoneSectionHeaderView.self, forHeaderFooterViewReuseIdentifier: "header")
//        mainTable.tableHeaderView = headerView
//        view.addSubview(mainTable)
        
//        mainTable.snp.makeConstraints { make in
//            make.left.right.bottom.equalToSuperview()
//            make.top.equalTo(NavigationContentTop)
//        }
        
        headerView.model = ""
    }
    
    @objc func imageTap() {
        UIApplication.shared.open(URL(string: "tel://" + headerView.phoneLb.text!)!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! FQOrganizationPhoneTableViewCell
        cell.model = ""
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.separatorInset = .init(top: 0, left: 20, bottom: 0, right: 20)
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        tableView.dequeueReusableHeaderFooterView(withIdentifier: "header")
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        58
    }
    
    override func setupNavigationItems() {
        super.setupNavigationItems()
        title = "机构电话"
    }
}
